<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('修改事件管理')" />
    <th:block th:include="include :: datetimepicker-css" />
    <th:block th:include="include :: select2-css" />
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <form class="form-horizontal m" id="form-evt-edit" th:object="${evt}">
            <input id="id" name="id" th:field="*{id}" type="hidden">
            <input id="ownerDeptId" name="ownerDeptId" th:field="*{ownerDeptId}" type="hidden"/>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">事件编号：</label>
                        <div class="col-sm-10">
                            <input name="bh" th:field="*{bh}" class="form-control" type="text" required>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">办结回复：</label>
                        <div class="col-sm-10">
                            <textarea id="completeFeedback" name="completeFeedback" class="form-control" rows="3" th:field="*{completeFeedback}"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">事件描述：</label>
                        <div class="col-sm-10">
                            <textarea id="contents" name="contents" class="form-control" rows="3" th:field="*{contents}"></textarea>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">结案回复：</label>
                        <div class="col-sm-10">
                            <textarea id="endFeedback" name="endFeedback" class="form-control" rows="3" th:field="*{endFeedback}"></textarea>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">事件类型：</label>
                        <div class="col-sm-10">
                            <div id="cxSelectEvtType" class="row">
                                <div class="col-sm-3">
                                    <select id="evtTypeId1" name="evtTypeId1" class="type1 form-control m-b" th:data-value="*{evtTypeId1}"></select>
                                </div>
                                <div class="col-sm-3">
                                    <select id="evtTypeId2" name="evtTypeId2" class="type2 form-control m-b" th:data-value="*{evtTypeId2}"></select>
                                </div>
                                <div class="col-sm-6">
                                    <select id="evtTypeId3" name="evtTypeId3" class="type3 form-control m-b" th:data-value="*{evtTypeId3}"></select>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">事件标签：</label>
                        <div class="col-sm-10">
                            <select name="tagId" class="form-control" th:with="type=${@dict.getType('evt_tag')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{tagId}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">所属组织：</label>
                        <div class="col-sm-10">
                            <input id="ownerDeptFullTxt" name="ownerDeptFullTxt" class="form-control" type="text" th:field="*{ownerDeptFullTxt}" required>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">所属部门：</label>
                        <div class="col-sm-10">
                            <div class="input-group">
                                <input id="ownerDeptName" name="ownerDeptName" class="form-control" type="text" onclick="selectDeptTree()" th:field="*{ownerDept.deptName}">
                                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">办结组织：</label>
                        <div class="col-sm-10">
                            <input id="doneDeptFullTxt" name="doneDeptFullTxt" class="form-control" type="text"  th:field="*{doneDeptFullTxt}" required>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">办结时间：</label>
                        <div class="col-sm-10">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="doneTime" name="doneTime" type="text" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" th:value="*{#calendars.format(doneTime,'yyyy-MM-dd HH:mm:ss')}" >
                            </div>
                        </div>
                    </div>
                </div>
            </div>

            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">结案组织：</label>
                        <div class="col-sm-10">
                            <input id="finishDeptFullTxt" name="finishDeptFullTxt" class="form-control" type="text"  th:field="*{finishDeptFullTxt}" required>
                        </div>
                    </div>
                </div>
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label is-required">登记时间：</label>
                        <div class="col-sm-10">
                            <div class="input-group date">
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                <input id="reportTime" name="reportTime" type="text" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" th:value="*{#calendars.format(reportTime,'yyyy-MM-dd HH:mm:ss')}" >
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="row">
                <div class="col-xs-6">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">数据来源：</label>
                        <div class="col-sm-10">
                            <select name="sourceId" class="form-control" th:with="type=${@dict.getType('evt_source')}">
                                <option value="">请选择</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}" th:field="*{sourceId}"></option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
        </form>
    </div>
    <div class="row">
        <div class="col-sm-offset-5 col-sm-10">
            <button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
            <button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <th:block th:include="include :: datetimepicker-js" />
    <th:block th:include="include :: select2-js" />
    <th:block th:include="include :: jquery-cxselect-js" />
    <script th:inline="javascript">
        var prefix = ctx + "system/evt";
        $(function() {
            // 事件类型下拉框
            $.cxSelect.defaults.url = ctx + "system/type/evtTypeCxSelectData";
            $('#cxSelectEvtType').cxSelect({
                selects: ['type1', 'type2', 'type3'],
                jsonValue: 'v',
                nodata: 'none'
            });

            //办结时间
            layui.use('laydate', function() {
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#doneTime',
                    type: 'datetime',
                    trigger: 'click'
                });
            });

            //登记时间
            layui.use('laydate', function() {
                var laydate = layui.laydate;
                laydate.render({
                    elem: '#reportTime',
                    type: 'datetime',
                    trigger: 'click'
                });
            });
        });

        $.validator.addMethod(
            "validDateTime",
            function(value, element) {
                return this.optional(element) || /^\d{4}-\d{2}-\d{2}\s(([0-1][0-9])|([2][0-3])):([0-5][0-9]):([0-5][0-9])$/.test(value);
            },
            "Please enter a valid date and time in YYYY-MM-DD hh:mm:ss format"
        );

        $("#form-evt-add").validate({
            onkeyup: false,
            rules:{
                bh:{
                    required: true,
                    minlength: 10,
                    maxlength: 30,
                    remote: {
                        url: prefix + "/checkBhUnique",
                        type: "post",
                        dataType: "json",
                        data: {
                            "bh": function() {
                                return $.common.trim($("#bh").val());
                            }
                        }
                    }
                },
                contents:{
                    required: true,
                    minlength: 10,
                    maxlength: 1000
                },
                evtTypeId1:{
                    required: true
                },
                evtTypeId2:{
                    required: true
                },
                evtTypeId3:{
                    required: true
                },
                ownerDeptFullTxt:{
                    required: true
                },
                ownerDeptId:{
                    required: true
                },
                reportDeptName:{
                    required: true
                },
                doneDeptFullTxt:{
                    required: true
                },
                finishDeptFullTxt:{
                    required: true
                },
                reportTime:{
                    required: true,
                    validDateTime: true
                }
            },
            messages: {
                "bh": {
                    remote: "事件编号已存在"
                },
                reportTime: {
                    validDateTime: "Please enter a date and time"
                }
            },
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                $.operate.saveTab(prefix + "/edit", $('#form-evt-edit').serialize());
            }
        }

        //选择部门
        function selectDeptTree() {
            var deptId = $.common.isEmpty($("#reportDeptId").val()) ? "100" : $("#reportDeptId").val();
            var url = ctx + "system/user/selectDeptTree/" + deptId;
            var options = {
                title: '选择部门',
                width: "380",
                url: url,
                callBack: selectDeptTreeSubmit
            };
            $.modal.openOptions(options);
        }
        function selectDeptTreeSubmit(index, layero){
            var body = $.modal.getChildFrame(index);
            $("#ownerDeptId").val(body.find('#treeId').val());
            $("#ownerDeptName").val(body.find('#treeName').val());
            $.modal.close(index);
        }
    </script>
</body>
</html>